import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';

import '../../config/kq_global.dart';
import '../../resources/kq_images.dart';
import '../../resources/kq_theme_colors.dart';
import '../../theme/kq_theme_manager.dart';
import '../divider/kq_divider.dart';

/// 详情专用View，仅用于查看，不能编辑
///
/// @author 周卓
///
/// 组成部分：【左边必填星号】+【左边标题】+ 【左边自定义View】 + 【右边内容】+ 【右边自定义View】+【右边箭头】
class KqDetailsItemView extends StatelessWidget {
  /// 左侧Text
  final String title;

  /// 右侧Text
  final String content;

  /// 标题的字体大小，默认24
  final double? titleFontSize;

  /// 内容的字体大小，默认24
  final double? contentFontSize;

  /// 标题的文字颜色
  final Color? titleTextColor;

  /// 内容的字体大小，默认24
  final Color? contentTextColor;

  /// 背景颜色
  final Color? backgroundColor;

  /// 是否必填
  final bool showMustInput;

  /// 是否显示右侧Text的下划线
  final bool showUnderline;

  /// 是否多行显示，默认true
  final bool multiLine;

  /// 最大行数
  final int? maxLines;

  /// 是否隐藏右侧文字
  final bool hideRightText;

  /// 是否显示右侧箭头
  final bool showRightArrow;

  /// 是否隐藏底部分割线
  final bool hideDivider;

  /// 整个Item点击
  final VoidCallback? onTaped;

  final Widget? customLeftView;

  /// 自定义右侧的View
  final Widget? customRightView;

  /// 右侧文字点击回调，考虑下划线文字可点击
  final Function(String text)? onRightTextTaped;

  const KqDetailsItemView({
    Key? key,
    required this.title,
    this.content = '',
    this.titleFontSize,
    this.contentFontSize,
    this.titleTextColor,
    this.contentTextColor,
    this.backgroundColor,
    this.showMustInput = false,
    this.showUnderline = false,
    this.hideRightText = false,
    this.showRightArrow = false,
    this.hideDivider = false,
    this.multiLine = true,
    this.maxLines,
    this.onTaped,
    this.onRightTextTaped,
    this.customLeftView,
    this.customRightView,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return KqInkWell(
      onTap: onTaped,
      backgroundColor: backgroundColor ?? KqThemeColors.bgDialog,
      child: Column(
        children: [
          Container(
            width: context.width,
            padding: EdgeInsets.fromLTRB(
                0.r,
                0,
                KqThemeManager.instance
                        .getConfig()
                        .formConfig
                        .paddingHorizontal ??
                    24.r,
                0),
            child: Row(
              children: [
                Container(
                  alignment: Alignment.centerRight,
                  width: KqThemeManager.instance
                          .getConfig()
                          .formConfig
                          .paddingHorizontal ??
                      24.r,
                  padding: EdgeInsets.only(
                      right: 2.r,
                      top: KqThemeManager.instance
                              .getConfig()
                              .formConfig
                              .paddingVertical ??
                          24.r,
                      bottom: KqThemeManager.instance
                              .getConfig()
                              .formConfig
                              .paddingVertical ??
                          24.r),
                  child: Text(
                    '*',
                    style: TextStyle(
                        color: showMustInput
                            ? KqThemeColors.textRed
                            : KqThemeColors.bgTransparent,
                        fontSize: KqThemeManager.instance
                                .getConfig()
                                .formConfig
                                .mustInputFontSize ??
                            20.sp),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(
                      vertical: KqThemeManager.instance
                              .getConfig()
                              .formConfig
                              .paddingVertical ??
                          24.r),
                  child: Text(
                    title,
                    style: TextStyle(
                        color: titleTextColor ?? KqThemeColors.text333,
                        fontSize: titleFontSize ??
                            KqThemeManager.instance
                                .getConfig()
                                .formConfig
                                .titleFontSize ??
                            24.sp),
                  ),
                ),
                SizedBox.fromSize(size: Size(4.r, 1.r)),
                customLeftView ?? Container(),
                SizedBox.fromSize(size: Size(6.r, 1.r)),
                hideRightText
                    ? Container()
                    : Expanded(
                        child: InkWell(
                        onTap: onRightTextTaped == null
                            ? null
                            : () => onRightTextTaped?.call(content),
                        child: Padding(
                          padding: EdgeInsets.symmetric(
                              vertical: KqThemeManager.instance
                                      .getConfig()
                                      .formConfig
                                      .paddingVertical ??
                                  24.r),
                          child: Text(
                            content,
                            textAlign: TextAlign.right,
                            maxLines: multiLine ? maxLines : 1,
                            overflow: multiLine ? null : TextOverflow.ellipsis,
                            style: TextStyle(
                                color:
                                    contentTextColor ?? KqThemeColors.text666,
                                fontSize: contentFontSize ??
                                    KqThemeManager.instance
                                        .getConfig()
                                        .formConfig
                                        .contentFontSize ??
                                    24.sp,
                                decoration: showUnderline
                                    ? TextDecoration.underline
                                    : TextDecoration.none),
                          ),
                        ),
                      )),
                customRightView ?? Container(),
                showRightArrow
                    ? Image.asset(
                        KqImages.commonIcJiantouRight16,
                        width: 24.r,
                        height: 24.r,
                        package: KqGlobal.packageName,
                      )
                    : Container(),
              ],
            ),
          ),

          /// 分割线
          Visibility(visible: !hideDivider, child: const KqDivider()),
        ],
      ),
    );
  }
}
